package com.hpq.user.controller;


import com.hpq.common.domain.vo.response.ApiResult;
import com.hpq.common.utils.RequestHolder;
import com.hpq.user.domain.vo.request.user.ModifyNameReq;
import com.hpq.user.domain.vo.request.user.WearingBadgeReq;
import com.hpq.user.domain.vo.response.user.UserBadgesResp;
import com.hpq.user.domain.vo.response.user.UserInfoResp;
import com.hpq.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/capi/user")
@Api(tags ="用户管理相关接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


//    @PostMapping(value = "/login")
//    @ApiOperation(value = "用户登录")
//    public ApiResult<UserLoginResp> login(@RequestBody UserLoginDTO userLoginDTO){
//
//        User user = userService.login(userLoginDTO);
//        Map<String,Object> claims = new HashMap<>();
//        claims.put(JwtConstant.UID,user.getId());
////        JwtUtils.createToken(claims);
//
//        return ApiResult.success();
//    }

    /**
     * 获取用户详情
     * @return
     */
    @GetMapping("/userInfo")
    @ApiOperation("获取用户详情")
    public ApiResult<UserInfoResp> getUserInfo(){
        // 获取当前用户
        UserInfoResp userInfo = userService.getUserInfo(RequestHolder.get().getUid());
        return ApiResult.success(userInfo);
    }

    /**
     *  修改用户名
     * @param req
     * @return
     */
    @PutMapping("/name")
    @ApiOperation("修改用户名")
    public ApiResult<Void> modifyName(@Valid @RequestBody ModifyNameReq req){
        userService.modifyName(RequestHolder.get().getUid(),req.getName());
        return ApiResult.success();
    }

    /**
     *  获取徽章列表
     * @return
     */
    @GetMapping("/badges")
    @ApiOperation("获取徽章列表")
    public ApiResult<List<UserBadgesResp>> getBadges(){
        return ApiResult.success(userService.getBadges(RequestHolder.get().getUid()));
    }
    /**
     * 佩戴徽章
     */
    @PutMapping("/wearBadge")
    @ApiOperation("佩戴徽章")
    public ApiResult<Void> wearBadge(@Valid @RequestBody WearingBadgeReq req){
        userService.wearBadge(RequestHolder.get().getUid(),req.getItemId());
        return ApiResult.success();
    }

}
